var util = require('../../utils/util.js')
var config = require('../../config.js')


Page({
    data: {
        dataList: [],
        dataType: 1, //数据类型：1新房2二手房3租房9装修
        moreButtonText: '更多房源',
        scroll_view_height:'577px'
    },
    onLoad: function () {
        wx.showNavigationBarLoading();
        var that = this;
        wx.getSystemInfo({
            success: function(res) {
                that.setData({
                    scroll_view_height: res.windowHeight - 45 + 'px'
                });
            }
        });


        getNewHouseList(this);
        wx.hideNavigationBarLoading()
    },
    bindscroll:function (e) {

    },
    toSearchPage: function () {
        wx.switchTab({
            url: '../search/index'
        })
    },
    toLocationPage: function () {
        console.log('跳转到城市选择页')
    },
    toMessagePage: function () {
        console.log('跳转到消息页')
    },
    toMore: function () {
        console.log('跳转到对应分类的更多页')
    },
    getHouseData: function (e) {
        var houseDataType = e.currentTarget.dataset.type;

        if (houseDataType == 1) {
            getNewHouseList(this);
            this.setData({
                dataType: houseDataType,
                moreButtonText: '更多房源'
            })
        }
        if (houseDataType == 2) {
            getOldHouseList(this);
            this.setData({
                dataType: houseDataType,
                moreButtonText: '更多房源'
            })
        }
        if (houseDataType == 3) {
            getRentHouseList(this);
            this.setData({
                dataType: houseDataType,
                moreButtonText: '更多房源'
            })
        }
        if (houseDataType == 9) {
            getDecorationCaseList(this);
            this.setData({
                dataType: houseDataType,
                moreButtonText: '更多装修案例'
            })
        }
    }
})

//获取新房源
function getNewHouseList(page) {
    util.showBusy('加载中..')
    var houseDataList = [];
    for (var i = 0; i < 10; i++) {
        var houseText = '万科金鱼国际';
        houseText = houseText.length > 6 ? houseText.substring(0, 6) + '..' : houseText;
        houseDataList.push({
            id:'new-'+i,
            houseImgUrl: 'http://www.tanbocloud.com:9001/icon/house13.png',
            houseTitle: houseText,
            houseUnitPrice: '21111元/平',
            isUptown: true,
            saleType: 2,
            isBrandLand: true,
            fitmentType:1,
            houseAreaRange:'40平-180平'
        })
    }

    page.setData({
        dataList: houseDataList
    })

    util.hideBusy();
}

//获取二手房源
function getOldHouseList(page) {
    util.showBusy('加载中..')

    var houseDataList = [];
    for (var i = 0; i < 10; i++) {
        houseDataList.push({
            id:'old-'+i,
            houseImgUrl: 'http://www.tanbocloud.com:9001/icon/house13.png',
            houseTitle: '大理聚福城好房满五年唯一好房哈哈',
            housePrice: '199万',
            houseUnitPrice: '21111元/平',
            houseBuildArea: '78平',
            houseRooms: '2室1厅1卫',
            houseTowards: '南北',
            isOverFiveyear: true,
            isOverTwoyear: false,
            isSole: true,
            isNearbySubway: true,
            isNewPulish: true,
            isBrandReal: true
        })
    }

    page.setData({
        dataList: houseDataList
    })

    util.hideBusy();
}

//获取租房源
function getRentHouseList(page) {
    util.showBusy('加载中..')

    var houseDataList = [];
    for (var i = 0; i < 10; i++) {
        houseDataList.push({
            id:'rent-'+i,
            houseImgUrl: 'http://www.tanbocloud.com:9001/icon/house13.png',
            houseTitle: '大理聚福城好房 价格低',
            houseUnitPrice: '21111元/月',
            houseBuildArea: '78平',
            houseRooms: '2室1厅1卫',
            houseRoad:'万寿',
            rentType:'不限租', //1合租2整租3不限租
            isNewPulish: true,
            isNearbySubway: true,
            fitmentType:1,
            agentType:1 //1代理人类型 1中介2个人
        })
    }

    page.setData({
        dataList: houseDataList
    })

    util.hideBusy();
}

//获取装修案例
function getDecorationCaseList(page) {
    util.showBusy('加载中..')

    var houseDataList = [];
    for (var i = 0; i < 10; i++) {
        houseDataList.push({
            id:'zx-'+i,
            zxImgUrl: 'http://www.tanbocloud.com:9001/img/zhuangxiu.jpg',
            zxTitle: '大理聚福城',
            zxPrice: '20万/半包',
            zxBuildArea: '78平',
            zxRooms:'3居室',
            zxFg:'欧式',
            zxCompany:'18度空间工作室',
            zxMain:'普通住宅'
        })
    }

    page.setData({
        dataList: houseDataList
    })

    util.hideBusy();
}